/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean.session;

import entity.ConvertedCustomerEntity;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * 
 */
@Stateless
public class ConvertedCustomerEntityFacade extends AbstractFacade<ConvertedCustomerEntity> {
    @PersistenceContext(unitName = "MacTeam-warPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public ConvertedCustomerEntityFacade() {
        super(ConvertedCustomerEntity.class);
    }   
    
    public int getConversionPercentage() {
        Query query = em.createQuery("SELECT COUNT(*) FROM CONVERTEDCUSTOMERENTITY C ");
        int numOfConvCust = ((Integer)query.getSingleResult()).intValue() + 1; 
        Query queryTwo = em.createQuery("SELECT COUNT(*) FROM SALESLEAD S ");
        int numOfSalesLead = ((Integer)queryTwo.getSingleResult()).intValue(); 
        
        int percentage = ((numOfConvCust/numOfSalesLead)*100);
        
        return percentage;
        
        //convertedCustomer.setSalesLeadCount(numOfSalesLead);
        //convertedCustomer.setPercentage(percentage);
        //em.persist(convertedCustomer); 
        //em.flush();
    }
    
    public List<ConvertedCustomerEntity> getConvertedCustomerEntity(){
     Query query = (Query)em.createQuery("Select c from ConvertedCustomerEntity c");
     //ArrayList list = new ArrayList<ConvertedCustomerEntity>();
     List<ConvertedCustomerEntity> list = query.getResultList();
       //  ConvertedCustomerEntity convertd = (ConvertedCustomerEntity) o;
      //   list.add(converted);
    // }
     return list;
}
}
